<template>
    <div>
        <h1>修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">房号</td>
                    <td><input type="text" v-model="info.Userfh"></td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td><input type="radio" name="set"  v-model="info.State" :value="true">上架
                        <input type="radio" name="set"  v-model="info.State" :value="false">下架</td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive, onMounted} from 'vue'
import axios from 'axios';
import { useRouter ,useRoute} from 'vue-router';
const router=useRouter();
const route =useRoute();
let info:any=reactive({
  Id:route.query.id,
  Name: '',
  Userfh: '',
  State: true,
})
onMounted(()=>{
    Find();
})
const Find=()=>{
    axios({
        url:'/api/User/Find',
        method:'get',
        params:{
            id:route.query.id
            
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info,res.data)
    })
    .catch((err)=>{
        console.log(err);
        
    })
}

const ok=()=>{
    axios({
        url:'/api/User/UpdateUser',
        method:'put',
        data:info
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1)
    {
        alert("房间名称重复")
        return;
    }
    if(res.data>0)
    {
        alert("修改成功")
        router.push('/fxShow');
        return;
    }
    else{
        alert("修改失败")
        return;
    }
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
</script>

<style scoped>

</style>